package org.ycx.upms.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.ycx.upms.common.constants.SecurityConstants;
import org.ycx.upms.dao.mapper.ISecSystemMapper;
import org.ycx.upms.dao.mapper.ISecUserMapper;
import org.ycx.upms.dao.model.SecUser;
import org.ycx.upms.dao.model.SecUserExample;
import org.ycx.upms.service.IIndexService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IndexServiceImpl implements IIndexService {

    @Autowired
    ISecUserMapper userMapper;

    @Autowired
    ISecSystemMapper systemMapper;

    @Override
    public Map<String, Object> findUserInfoAndSysInfo(String loginName, Integer appId) {
        Map<String, Object> map = new HashMap<String, Object> ();
        SecUserExample userExample = new SecUserExample ();
        userExample.createCriteria ().andLoginNameEqualTo (loginName);
        List<SecUser> users = this.userMapper.selectByExample (userExample);
        if (users != null && users.size () > 0) {
            map.put (SecurityConstants.USER_INFO, users.get (0));
            map.put(SecurityConstants.CURRENT_UID,users.get(0).getUid ());
        }
        map.put (SecurityConstants.SYSTEM_INFO, this.systemMapper.selectByPrimaryKey (appId));
        return map;
    }
}
